import 'package:flutter/material.dart';

class YJScaffold extends StatefulWidget {
  /// 子Widget
  final Widget child;

  /// 是否禁止物理返回
  final bool? isWillPopScope;

  /// 是否点击空白关闭软键盘
  final bool? isFocusNode;

  YJScaffold(
      {Key? key,
      required this.child,
      this.isWillPopScope = false,
      this.isFocusNode = false})
      : super(key: key);

  @override
  State<YJScaffold> createState() => _YJScaffoldState();
}

class _YJScaffoldState extends State<YJScaffold> {
  @override
  Widget build(BuildContext context) {
    return widget.isWillPopScope == true
        ? WillPopScope(
            onWillPop: () async {
              return false;
            },
            child: buildGestureDetector(context),
          )
        : buildGestureDetector(context);
  }

  Widget buildGestureDetector(BuildContext context) {
    return widget.isFocusNode == true
        ? GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () {
              FocusScope.of(context).requestFocus(FocusNode());
            },
            child: widget.child,
          )
        : widget.child;
  }
}
